<template>
  <div class="login-container">
    <div class="left">
      <!-- <img src="../../assets/common/login_back.png" alt="" /> -->
    </div>
    <div class="right">
      <h1>登录</h1>
      <div class="form">
        <el-form ref="form" :model="form">
          <el-form-item
            prop="mobile"
            :rules="[
              { required: true, message: '请输入手机号', trigger: 'blur' },
              {
                pattern: /^1[3-9][0-9]{9}$/,
                message: '请输入正确的手机号',
                trigger: 'blur',
              },
            ]"
          >
            <el-input
              v-model="form.mobile"
              clearable
              prefix-icon="el-icon-phone"
            />
          </el-form-item>
          <el-form-item
            prop="password"
            :rules="[
              { required: true, message: '请输入密码', trigger: 'blur' },
              {
                message: '密码长度为6-16位',
                pattern: /^.{6,16}$/,
                trigger: 'blur',
              },
            ]"
          >
            <el-input
              v-model="form.password"
              show-password
              clearable
              prefix-icon="el-icon-lock"
            />
          </el-form-item>
          <el-form-item>
            <el-checkbox v-model="checked"> 用户平台使用协议</el-checkbox>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="login">登录</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>
<script>
// import request from '@/utils/request'

export default {
  name: 'LoginCom',
  data() {
    return {
      form: {
        mobile: process.env.NODE_ENV === 'development' ? '13800000002' : '',
        password: process.env.NODE_ENV === 'development' ? 'hm#qd@23!' : ''
      },
      checked: false
    }
  },
  computed: {},
  created() {},
  methods: {
    login() {
      if (!this.checked) {
        return this.$message.error('请同意用户协议')
      }
      this.$refs.form.validate((valid) => {
        if (valid) {
          /*         request.post('/sys/login', this.form).then((res) => {

            this.$message.success(res.message)
          }) */
          this.$store
            .dispatch('user/setTokenAction', this.form)
            .then((res) => {
              if (res.success) {
                this.$router.push({ path: '/' })
                this.$message.success(res.message)
              }
            })
            .catch(() => {})
        } else {
          this.$message.error('登录失败')
          return false
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.login-container {
  width: 100vw;
  height: 100vh;
  background-color: #fff;
  display: flex;
  .left {
    flex: 3 1 0%;
    background: url("../../assets/common/login_back.png") no-repeat 50% / cover;
    padding: 0 100px;
    border-top-right-radius: 60px;
    /*    img {
      width: 100%;
      height: 100%;
    } */
  }
  .right {
    flex: 2 1 0%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    .form {
      width: 70%;
      ::v-deep.el-input__inner {
        background: #f4f5fb;
      }
      .el-button {
        width: 100%;
      }
    }
  }
}
</style>
